<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        img{
            position: absolute;
            top: 0;
            left: 0;
        }
    </style>
</head>
<body>
    <img src="./image/img.jpg" width="100" alt="">
</body>
</html>
<script>
    var image = document.querySelector("img")
    var targetX = 0
    var targetY = 0
    var leaderX = 0
    var leaderY = 0
    document.onclick = function(event){
        event = event || window.event
        targetX = event.clientX - image.offsetWidth/2
        targetY = event.clientY - image.offsetHeight/2
    }
    function fn(){
        leaderX = leaderX + (targetX - leaderX)/10
        leaderY = leaderY + (targetY - leaderY)/10
        image.style.left = leaderX+'px'
        image.style.top = leaderY+'px'
    }
    setInterval(fn, 30);

</script>